import java.util.Stack;

public class Solution3 {
    public boolean IsPopOrder (int[] pushV, int[] popV) {
        if(pushV.length==0)
            return false;

        int j = 0;
        Stack<Integer> stack = new Stack<>();
        for(int i = 0;i<pushV.length;i++){

            stack.push(pushV[i]);
            while(!stack.isEmpty()&&stack.peek()==popV[j]){
                stack.pop();
                j++;
            }
        }
        return stack.isEmpty();
    }
}
